package com.jzlg.miniec.service.impl;


import com.jzlg.miniec.entity.User;
import com.jzlg.miniec.mapper.UserMapper;

import com.jzlg.miniec.service.UserService;
import org.apache.ibatis.annotations.Insert;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author StCat
 * @Date 2021/11/29 10:49
 */
@Service
public class UserServiceImpl implements UserService {
    //@Autowired
    //注入mapper依赖
    @Resource
    private UserMapper userMapper;

    @Override
    public String findUserByNameAndPass(String username, String password) {

        Integer integer=userMapper.selectUserByNameAndPass(username,password);

        return integer==null?"亲，用户名密码有误":"ok";
    }

    @Override
    public boolean findUserByName(String username) {
        Integer temp=userMapper.selectUserByName(username);
        return temp==null?false:true;
    }

    @Override
    public String saveUser(User user){
        String tips="用户名已存在！";
        boolean flag=findUserByName(user.getUsername());
        if (!flag){
            //没有用户可以注册
            user.setLast_update(new Date());
            Integer temp=userMapper.insertUser(user);
          tips=(temp==null?"亲，注册有误":"注册成功");
        }
        return tips;
    }
    //用户登录的逻辑实现

}
